package com.tools.commons.utils;

import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;

/**
 * @author wangminggen
 */
public class EncryptDecryptUtil {
    private static final Logger log = LoggerFactory.getLogger(EncryptDecryptUtil.class);

    private EncryptDecryptUtil() {
    }

    public static String md5Hex(String str) {
        Assert.notNull(str, "str must not null");
        return DigestUtils.md5Hex(str);
    }

    public static String md5HexWithSalt(String str, String salt) {
        Assert.notNull(salt, "salt must not null");
        Assert.notNull(str, "str must not null");
        if (log.isDebugEnabled()) {
            log.debug("EncryptDecryptUtil md5 str => {},salt => {}", str, salt);
        }
        return DigestUtils.md5Hex(str + salt);
    }
}
